package com.lazy.web.controller;

import com.lazy.core.entity.ActivityInfo;
import com.lazy.core.service.ActivityInfoService;
import com.lazy.utils.annotation.Access;
import com.lazy.utils.utils.Result;
import com.lazy.utils.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * 活动信息
 */
@RestController
@RequestMapping(value = "/activityInfo")
public class ActivityController {

    @Autowired
    ActivityInfoService activityInfoService;

    @PostMapping(value = "/saveOrUpdate")
    @Access
    public Result saveOrUpdate(MultipartFile file, @Valid ActivityInfo activityInfo){
        Integer count = activityInfoService.saveOrUpdate(file,activityInfo);
        if(0 == count){
            return ResultUtils.errorResult();
        }else{
            return ResultUtils.successResult();
        }
    }

    @GetMapping(value = "/getLastActivityInfo")
    @Access
    public Result getLastActivityInfo(){
        ActivityInfo activityInfo = activityInfoService.getLastActivityInfo();
        return ResultUtils.objectResult(activityInfo);
    }
}
